var setZeroes = function(matrix) {
  const flagArr = [];

  const [m, n] = [matrix.length, matrix[0].length];

  for (let i = 0; i < m; i++) {
    for (let j = 0; j < n; j++) {
      if (matrix[i][j] === 0) {
        flagArr.push([i, j]);
      }
    }
  }

  for (let i = 0; i < flagArr.length; i++) {
    const temp = flagArr[i];
    for (let j = 0; j < n; j++) {
      matrix[temp[0]][j] = 0;
    }
    for (let j = 0; j < m; j++) {
      matrix[j][temp[1]] = 0;
    }
  }
  return matrix
};

const matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
console.log(setZeroes(matrix))